var VM=new Object();
ApiHost += "/{subFolder}";

$(function(){
    initPage();
    loadData();
});

//初始化页面
function initPage() {
    VM = new Vue({
        delimiters: ["[[", "]]"],
        el: '#app',
        data: {listdata: []}
    });
    $("#pageindex").val(0);
}

//加载数据
function loadData() {
    getListData(1);
}

//获取列表数据
function getListData(pageindex) {
    if (pageindex == undefined) pageindex = 1;
    $("#pageindex").val(pageindex);
    $("#pagesize").val(Page.pagesize);

    var url = ApiHost + "/{tblName}List";
    var formData = $('#formquery').serialize();
    $.ajax({
        type: "POST",
        url: url,
        dataType: "json",
        data:  formData ,
        error: function (request) {
            ajaxError(request,$(this));
        },
        success: function (result) {
            //console.log(result);
            ajaxSuccess(result, $(this));
            VM.listdata = result.data.rows;
            pagerInit(pageindex, result.data.total);

        }
    });
}

//打开编辑窗口
function popupEdit(id) {
    var url = ApiHost + "/{tblName}Add/?id="+id;
    openLayer(url,"修改");
}

//删除记录
function popupDelete(id) {
    if(confirm("确定要删除此记录吗？删除后不可恢复！")){
        var url = ApiHost + "/{tblName}Delete";
        $.ajax({
                type: "post",
                url: url,
                data: { 
					id:id 
				},
                dataType: "json",
                error: function (request) {
                    ajaxError(request, $(this));
                },
                success: function (result) {
                    ajaxSuccess(result, $(this));
                    var code=result.statecode;
                    if(code==0){
                        //layerAlert("删除成功");
                        layerCallBack();
                    }else{
                        layerAlert("提交失败："+result.message);
                    }
                }
            }
        );

    }

}

//回调函数
function layerCallBack() {
    setTimeout('loadData()',200);

}